package day05;

import java.awt.Color;
import java.awt.Container;
import java.awt.Dimension;
import java.awt.FlowLayout;
import java.awt.Font;
import java.awt.Graphics;
import java.awt.Image;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import javax.swing.ImageIcon;
import javax.swing.JButton;
import javax.swing.JDialog;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JPasswordField;
import javax.swing.JTextField;

public class Denglulei extends JFrame {
		Container ct;//创建一个容器
		BackgroundPanel bgp;//创建背景画板
		JLabel j1=new JLabel("快登录吧弟弟");		
		JLabel j2=new JLabel("搁着给我输用户名了弟弟：");
		JLabel j3=new JLabel("搁着给我输密码了弟弟：");
		JPasswordField j4=new JPasswordField();
		JTextField j5=new JTextField();
		JButton j6=new JButton("登录");
		JButton j7=new JButton("退出");
		private ClientContext clientcontext;
		public ClientContext getClientcontext() {
			return clientcontext;
		}
		public void setClientcontext(ClientContext clientcontext) {
			this.clientcontext = clientcontext;
		}
		Denglulei(){
			 init();
			 this.setTitle("登录界面哦弟弟");
		     this.setResizable(false);
		     this.setSize(800, 600);
		     this.setLocationRelativeTo(null);
		     this.setDefaultCloseOperation(EXIT_ON_CLOSE);
//		     this.setVisible(true);
//		     start();


		 }
		void init(){
			ct=this.getContentPane();
			bgp=new BackgroundPanel((new ImageIcon("风景1.jpg")).getImage());
	        this.setLayout(null);
	        bgp.setBounds(0,0,800,600);
			this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
	        //标题标签
	        j1.setBounds(240, 50, 500, 100);//x坐标10，y坐标0，组件宽100，高50
	        j1.setFont(new Font("宋体",Font.BOLD,50));
	        j1.setForeground(new Color(	
	        		240,128,128));
	        //用户名标签
	        j2.setBounds(30, 150, 300, 100);
	        j2.setFont(new Font("宋体",Font.BOLD,20));
	        j2.setForeground(new Color(250,235,215));
	        //用户名输入框
	        j5.setBounds(300,175, 400, 50);
	        j5.setFont(new Font("宋体",Font.BOLD,20));
	        //密码标签
	        j3.setBounds(30, 250, 300, 100);
	        j3.setFont(new Font("宋体",Font.BOLD,20));
	        j3.setForeground(new Color(250,235,215));
	        //密码框
	        j4.setBounds(300, 275, 400, 50);
	        j4.setFont(new Font("宋体",Font.BOLD,60));
	        //登录按钮
	        j6.setBounds(225, 420, 100, 60);
	        j6.setFont(new Font("黑体",Font.BOLD,17));	        
	        //退出按钮
	        j7.setBounds(475, 420, 100, 60);
	        j7.setFont(new Font("黑体",Font.BOLD,17));
	        ct.add(j1);
	        ct.add(j2);
	        ct.add(j3);
	        ct.add(j4);
	        ct.add(j5);
	        ct.add(j6);
	        ct.add(j7);
	        ct.add(bgp,new Integer(Integer.MIN_VALUE));
			j6.addActionListener(new ActionListener() {
				public void actionPerformed(ActionEvent e) {
					clientcontext.login();
				}
			});
			j7.addActionListener(new ActionListener() {
				

				public void actionPerformed(ActionEvent e) {
					clientcontext.out();
					
				}
			});

	    }
//		public void start() {
//
//			
////			SimpleListener sl=new SimpleListener();
//			j6.addActionListener(sl);
//            j7.addActionListener(sl);
//			
//		}
		public void shutdown() {
			this.dispose();
		}
		public void tanchuang() {
			JDialog jl=new JDialog(this,"错误");
			jl.setSize(400, 100);
		    jl.setVisible(true);
		    jl.setLayout(null);
		    JLabel pp=new JLabel("用户名或密码错误");
		    pp.setBounds(0,0, 400, 50);
		    pp.setFont(new Font("宋体", Font.BOLD,25));
		    jl.add(pp);
		    
		}

//       private class SimpleListener implements ActionListener{
// 
//    	   	public void actionPerformed(ActionEvent e){
//
//    	   	String buttonName = e.getActionCommand();
//    	   	if(buttonName.equals("登录")){
//    	   		System.out.println("1");
////    	   		System.out.println(j5.getText());
////    	   		System.out.println(j4.getPassword());
////    	   		String c=String.valueOf(j4.getPassword());
////    	   		if(j5.getText().equals("弟弟")&&c.equals("aaa")) {
////    	   			Caidanlei caidan=new Caidanlei();
////    	   			caidan.setVisible(true);
////    	   			caidan.j6.setText(j5.getText()+"你好");
////    	   			shutdown();
////    	   			
//    	   	}else if(buttonName.equals("退出")) {
//   	   	     shutdown();
//    	   	
//       		}
//       }
//      }
		
       public  String getUseId() {
    	   return j5.getText();
    			 
       }
       public String getPassword() {
    	   return new String(j4.getPassword());
       }
       
       class BackgroundPanel extends JPanel{
       	Image im;
       	public BackgroundPanel(Image im)
       	{
       		this.im=im;
       		this.setOpaque(true);
       	}
       	
       	public void paintComponent(Graphics g)
       	{
       		super.paintComponents(g);
       		g.drawImage(im,0,0,this.getWidth(),this.getHeight(),this);
       		
       	}

       }
       
}
